package org.tinygroup.ansjanalyzer;

import java.io.IOException;
import java.io.Reader;
import java.util.List;

import org.ansj.domain.Term;
import org.ansj.splitWord.analysis.IndexAnalysis;
import org.apache.lucene.analysis.Tokenizer;

/**
 * 对应IndexAnalysis 面向索引的分词
 * @author yancheng11334
 *
 */
public class IndexAnalyzer extends LuceneAnalyzer{

	protected Tokenizer createTokenizer(Reader reader) {
		return new IndexAnalysisTokenizer(reader);
	}

	final class IndexAnalysisTokenizer extends LuceneTokenStream {

		protected IndexAnalysisTokenizer(Reader input) {
			super(input);
		}

		protected TokenStreamWrapper createTokenStreamWrapper(Reader input) throws IOException {
			return new IndexAnalysisWrapper(input);
		}
		
	}
	
	class IndexAnalysisWrapper extends AbstractTokenStreamWrapper{

		public IndexAnalysisWrapper(Reader input) throws IOException {
			super(input);
		}

		public List<Term> parse(String str) {
			return IndexAnalysis.parse(str).getTerms();
		}
		
	}


}
